<?php
 

define('IN_SCRIPT',1);

/* Get all the required files and functions */
require_once('hd_settings.inc.php');
require_once('language/'.$hd_settings['language'].'.inc.php');
require_once('inc/common.inc.php');
hd_session_start();
hd_isLoggedIn();

/* Print header */
require_once('inc/header.inc.php');

if (!empty($_POST['action'])) {update_profile();}

/* Print admin navigation */
require_once('inc/show_admin_nav.inc.php');
?>

</td>
</tr>
<tr>
<td>

<h3 align="center"><?php echo $hdlang['profile_for'].' <b>'.$_SESSION['user']; ?></b></h3>

<p align="center"><?php echo $hdlang['req_marked_with']; ?> <font class="important">*</font></p>

<form method="POST" action="profile.php" name="form1">

<!-- Contact info -->
<table border="0">
<tr>
<td align="right" width="200"><?php echo $hdlang['name']; ?>: <font class="important">*</font></td>
<td align="left" width="550"><input type="text" name="name" size="25"
maxlength="50" value="<?php echo $_SESSION['name']; ?>"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['email']; ?>: <font class="important">*</font></td>
<td align="left" width="550"><input type="text" name="email" size="30"
maxlength="255" value="<?php echo $_SESSION['email']; ?>"></td>
</tr>
</table>

<hr>

<!-- Password -->
<table border="0">
<tr>
<td align="right" width="200"><?php echo $hdlang['new_pass']; ?>: </td>
<td align="left" width="550"><input type="password" name="newpass" size="30"
maxlength="20"></td>
</tr>
<tr>
<td align="right" width="200"><?php echo $hdlang['confirm_pass']; ?>: </td>
<td align="left" width="550"><input type="password" name="newpass2" size="30"
maxlength="20"></td>
</tr>
</table>

<hr>

<!-- signature -->
<table border="0">
<tr>
<td align="right" valign="top" width="200"><?php echo $hdlang['signature_max']; ?>:</td>
<td align="left" width="550"><textarea name="signature" rows="6" cols="40"><?php echo $_SESSION['signature']; ?></textarea><br>
 </td>
</tr>
</table>

<!-- Notify about new requests and replies -->
<p align="center"><label><input type="checkbox" name="notify" value="1" <?php
if ($_SESSION['notify']) {echo "checked";}
?> > <?php echo $hdlang['notify_new_posts']; ?>.</label></p>

<!-- Submit -->
<p align="center"><input type="hidden" name="action" value="update">
<input type="submit" value="<?php echo $hdlang['update_profile']; ?>" class="button"></p>

<p>&nbsp;</p>

<!-- HR -->
<p>&nbsp;</p>

<?php
require_once('inc/footer.inc.php');
exit();


/*** START FUNCTIONS ***/

function update_profile() {
global $settings, $hdlang;

$_SESSION['name']=hd_input($_POST['name'],$hdlang['enter_your_name']);
$_SESSION['email']=hd_validateEmail($_POST['email'],$hdlang['enter_valid_email']);
$_SESSION['signature']=hd_input($_POST['signature']);
if (hd_input($_POST['notify'])) {$_SESSION['notify']=1;}
else {$_SESSION['notify']=0;}
if (strlen($_SESSION['signature'])>255) {hd_error($hdlang['signature_long']);}

/* Change password? */
if (!empty($_POST['newpass']))
{
    $newpass=hd_PasswordSyntax($_POST['newpass'],$hdlang['password_not_valid']);
    $newpass2=hd_input($_POST['newpass2'],$hdlang['confirm_user_pass']);
    if ($newpass != $newpass2) {hd_error($hdlang['passwords_not_same']);}
    $_SESSION['pass']=$newpass;
}

/* Connect to database */
require_once('inc/database.inc.php');
hd_dbConnect() or hd_error("$hdlang[cant_connect_db] $hdlang[contact_webmsater] $hd_settings[webmaster_mail]!");

$sql = "UPDATE `hd_users` SET `name`='$_SESSION[name]',`email`='$_SESSION[email]',
`signature`='$_SESSION[signature]',`pass`=MD5('$_SESSION[pass]'),`notify`='$_SESSION[notify]' WHERE `id`='$_SESSION[id]' LIMIT 1";
$result = hd_dbQuery($sql) or hd_error("$hdlang[cant_sql]: $sql</p><p>$hdlang[mysql_said]:<br>".mysql_error()."</p><p>$hdlang[contact_webmsater] $hd_settings[webmaster_mail]");

/* Print admin navigation */
require_once('inc/show_admin_nav.inc.php');
?>

</td>
</tr>
<tr>
<td>

<p>&nbsp;</p>
<h3 align="center"><?php echo $hdlang['profile_updated']; ?></h3>

<p>&nbsp;</p>

<p align="center"><?php echo $hdlang['profile_updated_success']; ?>.</p>

<p align="center"><a href="profile.php"><?php echo $hdlang['view_profile']; ?></a> |
<a href="admin_main.php"><?php echo $hdlang['main_page']; ?></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>

<!-- HR -->
<p>&nbsp;</p>

<?php
require_once('inc/footer.inc.php');
exit();
} // End update_profile()

?>
